package models

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	Name  string  `json:"name"`
	Price float64 `json:"price"`
	Img   string  `json:"img"`
	Intro string  `json:"intro"`
}

func OrderList(page, pageSize int) ([]Order, int64, error) {
	var orders []Order
	var total int64
	if err = DB.Model(Order{}).Count(&total).Error; err != nil {
		return nil, 0, err
	}
	if err = DB.Model(Order{}).Order("price desc").Offset((page - 1) * pageSize).Limit(pageSize).Find(&orders).Error; err != nil {
		return nil, 0, err
	}
	return orders, total, nil
}
